package www.openteam.com.adapter.PrdctnMngmnt;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.SRCKPlanMsg;

/**
 * Created by Administrator on 2019-06-21.
 */

public class SRCKPlanAdp extends RecyclerView.Adapter<SRCKPlanAdp.ViewHolder> {

    Context context;
    List<SRCKPlanMsg.DataBeanX.DataBean> dataBeanList = new ArrayList<>();
    SRCKPlanClickBack srckPlanClickBack;
    double mClickTime = 0;



    public void setSrckPlanClickBack(SRCKPlanClickBack srckPlanClickBack) {
        this.srckPlanClickBack = srckPlanClickBack;
    }

    public SRCKPlanAdp(Context context, List<SRCKPlanMsg.DataBeanX.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    public interface SRCKPlanClickBack {
        void postdata(SRCKPlanMsg.DataBeanX.DataBean dataBean);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_srck_plan, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final SRCKPlanMsg.DataBeanX.DataBean dataBean = dataBeanList.get(position);
        holder.srckPlanAmount.setText(dataBean.getAllsum());
        holder.srckPlanPjctNum.setText(dataBean.getProduceno());
        holder.srckPlanPjctName.setText(dataBean.getProcname());
        holder.srckPlanUnit.setText(dataBean.getGroupname());
        holder.srckPlanParts.setText(dataBean.getPartid());
        holder.srckPlanProcno.setText(dataBean.getProcno());
        holder.srckPlanProcneName.setText(dataBean.getProcname());
        holder.srckPlanIssueNum.setText(dataBean.getAlreadypay());
        holder.srckPlanPlannumbnow.setText(dataBean.getPlannumbnow());
        holder.srckPlanPjctReq.setText(dataBean.getProcremark());
        holder.srckPlanOtherState.setText(dataBean.getOtherremark());
        holder.srckPlanOsplanrdsno.setText(dataBean.getOsplanrdsno());
        holder.srckPlanosplanId.setText(dataBean.getOSplanpid()+"");
        holder.srckPlanLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (System.currentTimeMillis() - mClickTime <600) {
                    if (null!=srckPlanClickBack){
                        srckPlanClickBack.postdata(dataBean);
                    }
                } else {
                    mClickTime = System.currentTimeMillis();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.SRCKPl_pjctNum)
        TextView srckPlanPjctNum;
        @Bind(R.id.srck_plan_pjctCode)
        TextView srckPlanPjctCode;
        @Bind(R.id.srck_plan_pjctName)
        TextView srckPlanPjctName;
        @Bind(R.id.srck_plan_Unit)
        TextView srckPlanUnit;
        @Bind(R.id.srck_plan_parts)
        TextView srckPlanParts;
        @Bind(R.id.srck_plan_procno)
        TextView srckPlanProcno;
        @Bind(R.id.srck_plan_proceName)
        TextView srckPlanProcneName;
        @Bind(R.id.srck_plan_amount)
        TextView srckPlanAmount;
        @Bind(R.id.srck_plan_issueNum)
        TextView srckPlanIssueNum;
        @Bind(R.id.srck_plan_plannumbnow)
        TextView srckPlanPlannumbnow;
        @Bind(R.id.srck_plan_osplanrdsno)
        TextView srckPlanOsplanrdsno;
        @Bind(R.id.srck_plan_osplanId)
        TextView srckPlanosplanId;
        @Bind(R.id.srck_plan_pjctReq)
        TextView srckPlanPjctReq;
        @Bind(R.id.srck_plan_otherState)
        TextView srckPlanOtherState;
        @Bind(R.id.srck_plan_line)
        LinearLayout srckPlanLine;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
